<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            width: 500px;
            margin: 20px auto;
            text-align: center;
            padding: 0px;
        }
        
        #foot {
            width: 500px;
            margin: 3px auto;
        }
        
        #foot div {
            width: 200px;
            float: right;
        }
        
        thead {
            background-color: cornflowerblue;
        }
        
        table,
        td,
        th {
            padding: 0px;
            border-collapse: collapse;
            padding: 5px 3px;
            height: 20px;
            line-height: 20px;
            border-bottom: 1px solid #777;
        }
        
        .bgeven {
            background-color: rgba(35, 196, 129, 0.473);
        }
        
        .bgodd {
            background-color: beige;
        }
    </style>
</head>

<body>


    <table>
        <thead>
            <tr>
                <td>
                    <input type="checkbox" name="all" id="all">
                </td>
                <td>序号</td>
                <td>姓名</td>
                <td>年龄</td>
                <td>成绩</td>
                <td>
                    操作
                </td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    <input type="checkbox" name="item" id="" value="">
                </td>

                <td>1</td>
                <td>张三</td>
                <td>20</td>
                <td>90.5</td>
                <td>
                    <a href="javascript:void(0);">删除</a>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" name="item" id="" value="">
                </td>

                <td>2</td>
                <td>李四</td>
                <td>21</td>
                <td>89</td>
                <td>
                    <a href="javascript:void(0)">删除</a>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" name="item" id="" value="">
                </td>

                <td>3</td>
                <td>王五</td>
                <td>20</td>
                <td>60</td>
                <td>
                    <a href="javascript:void(0);">删除</a>
                </td>
            </tr>

            <tr>
                <td>
                    <input type="checkbox" name="item" id="" value="">
                </td>

                <td>4</td>
                <td>王刘</td>
                <td>15</td>
                <td>14</td>
                <td>
                    <a href="javascript:void(0);">删除</a>
                </td>
            </tr>
        </tbody>

    </table>
    <div id="foot">
        <button>反选</button>
        <button id="del">删除选中</button>
        <div id="price">
            <span>总分</span>
            <span id="total">0.0</span>
        </div>

    </div>
    <script>
        var all = document.querySelector('#all');
        var items = document.querySelector('tbody').querySelectorAll('input');
        var un = document.querySelector('button');
        var del = document.querySelector('#del');
        var a = document.querySelectorAll('a');
        var total = document.querySelector('#total');

        function sum() {
            total.innerHTML = 0;
            for (var i = 0; i < items.length; i++) {
                if (items[i].checked == true) {
                    total.innerHTML = total.innerHTML - 0 + parseFloat(items[i].parentNode.parentNode.children[4].innerHTML);
                }
            }
        }
        all.addEventListener('click', function() {
            for (var i = 0; i < items.length; i++) {
                items[i].checked = this.checked;
            }
            sum();
        })

        function cleck() {
            var t = true;
            for (var i = 0; i < items.length; i++) {
                if (!items[i].checked) {
                    t = false;
                }
            }
            all.checked = t;
            sum();
        }
        for (var i = 0; i < items.length; i++) {
            items[i].addEventListener('click', function() {
                cleck();
            });
        }
        un.addEventListener('click', function() {
            for (var i = 0; i < items.length; i++) {
                items[i].checked = !items[i].checked;
            }
            cleck();
        })
        for (var i = 0; i < items.length; i++) {
            a[i].addEventListener('click', function() {
                this.parentNode.parentNode.firstElementChild.firstElementChild.checked = false;
                this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
                cleck();
            });
        }
        del.addEventListener('click', function() {
            for (var i = 0; i < items.length; i++) {
                if (items[i].checked) {
                    items[i].checked = false;
                    items[i].parentNode.parentNode.parentNode.removeChild(items[i].parentNode.parentNode);
                }
            }
            cleck();
        })
    </script>

</body>

<script>
</script>

</html>